﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Kaskelot.SP.UI.Analys.ViewModel
{
    public class Entity : INotifyPropertyChanged
    {
        private List<Field> fields;
        public List<Field> Fields
        {
            get
            {
                return this.fields;
            }
            set
            {
                this.fields = value;
                this.fields.ForEach(f => 
                    f.PropertyChanged += field_PropertyChanged);
            }
        }

        void field_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName != "IsEnabled")
            {
                OnPropertyChanged("Fields");
            }
        }

        public string Name { get; set; }

        private bool isEnabled;
        public bool IsEnabled
        {
            get
            {
                return isEnabled;
            }
            set
            {
                if (this.isEnabled != value)
                {
                    this.isEnabled = value;
                    this.OnPropertyChanged("IsEnabled");
                }
            }
        }

        private bool expanded;
        public bool Expanded
        {
            get
            {
                return expanded;
            }
            set
            {
                if (this.expanded != value)
                {
                    this.expanded = value;
                    this.OnPropertyChanged("Expanded");
                }
            }
        }

        public List<string> CannotBeCombinedWith { get; set; }

        private bool isChecked;
        public bool Checked
        {
            get
            {
                return this.isChecked;
            }
            set
            {
                if (this.isChecked != value)
                {
                    this.isChecked = value;
                    this.OnPropertyChanged("Checked");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public bool IsPrimary { get; set; }
    }
}
